﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;

namespace NtpChat.Client.ViewModel
{

    /// </summary>
    public class LoginViewModel : ViewModelBase
    {
        public LoginViewModel()
        {

        }


        public const string UserNamePropertyName = "UserName";

        private string userName = "";

        public string UserName
        {
            get
            {
                return userName;
            }

            set
            {
                if (userName == value)
                {
                    return;
                }

                var oldValue = userName;
                userName = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(UserNamePropertyName);
            }
        }

        private RelayCommand checkLoginCommand;

        public RelayCommand CheckLoginCommand
        {
            get 
            {
                if (checkLoginCommand == null)
                    checkLoginCommand = new RelayCommand(CheckLogin);
                return checkLoginCommand;
            }
        }
        
        public void CheckLogin()
        {
            Messenger.Default.Send<string>(UserName);
        }
    }
}